package com.tc.service;

import com.tc.dao.UserDao;
import com.tc.dto.Envelope;
import com.tc.entity.UserEntity;
import com.tc.util.PasswordUtil;

public class UserService {

    private UserDao userDao;
    public UserService(){
        this.userDao=new UserDao();
    }

    /**验证用户名密码是否匹配
     *
     * @param id
     * @param password
     * @return
     */
    public Envelope validUser(String id,String password){
        UserEntity userEntity= null;
        try {
            userEntity = userDao.get(id);
        } catch (Exception e) {
            e.printStackTrace();
            return Envelope.dbError;
        }
        if(userEntity==null)
            return new Envelope(1,"用户不存在",null);
        if(!userEntity.getPassword().equals(PasswordUtil.getMd5(password)))
            return new Envelope(2,"用户名密码不匹配",null);
        return Envelope.success;
    }

    public static void main(String args[]){
        UserService userService=new UserService();
        System.out.println(userService.validUser("zekdot","123456"));
    }
}
